package com.example.controller;

import com.example.common.Result;
import com.example.service.ActivityRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "志愿服务统计分析")
@RestController
@RequestMapping("/api/activity/statistics")
@RequiredArgsConstructor
public class ActivityStatisticsController {

    private final ActivityRecordService activityRecordService;

    @Operation(summary = "获取志愿者服务统计")
    @GetMapping("/volunteer/{volunteerId}")
    public Result<Map<String, Object>> getVolunteerServiceStats(
            @Parameter(description = "志愿者ID") @PathVariable Long volunteerId) {
        return Result.success(activityRecordService.getVolunteerServiceStats(volunteerId));
    }

    @Operation(summary = "获取活动服务统计")
    @GetMapping("/activity/{activityId}")
    public Result<Map<String, Object>> getActivityServiceStats(
            @Parameter(description = "活动ID") @PathVariable Long activityId) {
        return Result.success(activityRecordService.getActivityServiceStats(activityId));
    }

    @Operation(summary = "获取时间段内的服务统计")
    @GetMapping("/date-range")
    public Result<Map<String, Object>> getServiceStatsByDateRange(
            @Parameter(description = "开始日期 (yyyy-MM-dd)") @RequestParam String startDate,
            @Parameter(description = "结束日期 (yyyy-MM-dd)") @RequestParam String endDate) {
        return Result.success(activityRecordService.getServiceStatsByDateRange(startDate, endDate));
    }

    @Operation(summary = "获取志愿者服务排行榜")
    @GetMapping("/ranking")
    public Result<List<Map<String, Object>>> getVolunteerRankingList(
            @Parameter(description = "限制数量") @RequestParam(defaultValue = "10") Integer limit) {
        return Result.success(activityRecordService.getVolunteerRankingList(limit));
    }

    @Operation(summary = "获取活动参与情况分析")
    @GetMapping("/participation/{activityId}")
    public Result<Map<String, Object>> getActivityParticipationAnalysis(
            @Parameter(description = "活动ID") @PathVariable Long activityId) {
        return Result.success(activityRecordService.getActivityParticipationAnalysis(activityId));
    }

    @Operation(summary = "获取服务类型分布统计")
    @GetMapping("/service-type")
    public Result<List<Map<String, Object>>> getServiceTypeDistribution() {
        return Result.success(activityRecordService.getServiceTypeDistribution());
    }
} 